﻿//--------------------------------------------------------------------------------------------------------------
// <copyright file="CSPAuxiliaryMenu.cs" company="Microsoft Corporation" author="David Martos" date="01/01/2008">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Collections;
using System.Reflection;
using System.ComponentModel;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Publishing;


using CSP.Core;

namespace CSP.WebParts
{
    /// <summary>
    /// This webpart gets the POI categories
    /// </summary>
    [Guid("B7C7E7DC-9E90-4fa5-BE9C-28BD5C68E60F")]
    public class CSPPoiCategories : BaseWebPart
    {

        #region members
        private string listSite;
        private string listName;
        UserControls.CSPKeyAttractionsWUC control;
        private const string ListSiteDefault = "visitors";
        private const string ListNameDefault = "KeyAttractions";
        #endregion

        #region properties
        /// <summary>
        /// This property is used by any webpart that uses an XSL transformation to store the path
        /// of the XSL Stylesheet. The format should be: 'Style Library/XSL Style Sheets/File.xsl'
        /// </summary>
        [WebBrowsable(true), Personalizable(true)]
        [ResourcesAttribute("MapParamPoiCategoriesSite", "CSPWebPartParameterCategory", "MapParamPoiCategoriesSiteDescription")]
        [DefaultValue(ListSiteDefault)]
        public string ListSite
        {
            get { return listSite; }
            set { listSite = value; }
        }

        [WebBrowsable(true), Personalizable(true)]
        [ResourcesAttribute("MapParamPoiCategoriesList", "CSPWebPartParameterCategory", "MapParamPoiCategoriesListDescription")]
        [DefaultValue(ListNameDefault)]
        public string ListName
        {
            get { return listName; }
            set { listName = value; }
        }
        #endregion


        #region methods
        /// <summary>
        /// Constructor
        /// </summary>
        public CSPPoiCategories()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// Fired on page create child control, loads the ASCX file
        /// </summary>
        protected override void CreateChildControls()
        {

            base.CreateChildControls();
            try
            {
                if (listSite.Equals(string.Empty) || listName.Equals(string.Empty))
                {
                    this.LogMessage(this.LoadResource(WebPartConstants.CSPGenericErrorMessage), WebPartConstants.CSPKeyAttractionsProperyListErrorMessage);
                }
                else
                {
                    control = (UserControls.CSPKeyAttractionsWUC)this.Page.LoadControl(WebPartConstants.CSPKeyAttractionsWUC);
                    control.WrapperWebPart = this;
                    control.ListName = this.listName;
                    control.ListSite = this.listSite;
                    this.Controls.Add(control);
                }
            }
            catch (CSP.Core.CSPException cspex)
            {
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
            catch (Exception ex)
            {
                this.LogMessage(this.LoadResource(WebPartConstants.CSPGenericErrorMessage), this.GetType().Name, ex);
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
        }
        #endregion


    }
}
